package com.xinan.system.curd;

import java.util.List;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;

/**
 * Blog model.
 */
@TableBind(tableName = "table_meta")
public class TableMeta extends Model<TableMeta> {
    public static final TableMeta dao = new TableMeta();

    public List<TableMeta> findAll() {
        return find("select * from table_meta order by id asc");
    }

    public List<TableMeta> findByFields(String tableName,String fields) {
        fields = "'" + fields.replace(",","','")+"'";
        return find("select * from table_meta where tablename=? and fieldname in (" + fields + ") order by disporder",tableName);
    }

    public List<Record> findAllTables() {
        return Db.find("select distinct tablename id,descinfo text from table_meta order by tablename");
    }

    public List<Record> findAllFields(String tableName) {
        return Db.find("select distinct fieldname id,fielddesc text from table_meta where tablename=? order by disporder", tableName);
    }

    public String getId() {
        return get("id");
    }

    public String getTableName() {
        return get("tablename");
    }

    public String getDescInfo() {
        return get("descinfo");
    }

    public String getFieldName() {
        return get("fieldname");
    }

    public String getFieldDesc() {
        return get("fielddesc");
    }

    public String getDataType() {
        return get("datatype");
    }

    public String getDataLength() {
        return get("datalength");
    }

    public String getFkTable() {
        return get("fktable");
    }

    public String getFkId() {
        return get("fkid");
    }

    public String getFkName() {
        return get("fkname");
    }

    public String getFkWhere() {
        return get("fkwhere");
    }

    public String getFkPid() {
        return get("fkpid");
    }

    public String getCodeType() {
        return get("codetype");
    }
}